home *** CD-ROM | disk | FTP | other *** search
- public class Generator extends Codex {
- private String _templateName;
- private float _delay;
- private float _frequency;
- private int _maxThings;
- private int _maxAlive;
- private int numThings;
- private int numAlive;
- private int numFrames;
- private float[] pos;
- private CodexThing generatorThing;
- private CodexThing generatedThing;
- private int generatedGuid;
- public static String[] _params = new String[]{"Template to generate", "Delay;10.0", "Frequency;60.0", "Max Things;20", "Max Alive;0"};
-
- public void beginscene(int clientGuid, int captureID) {
- if (!((double)this._frequency < 0.1)) {
- this.generatorThing = new CodexThing(((Codex)this).GetClassThing());
- if (this.generatorThing != null) {
- this.numFrames = this.generatorThing.GetNumFrames();
- if (this.numFrames != 0) {
- this.pos = this.generatorThing.GetFramePosition(1);
- }
-
- if ((double)this._delay > 0.1) {
- ((Codex)this).SetTimer(this._delay);
- } else {
- ((Codex)this).SetTimer(this._frequency);
- }
- }
-
- }
- }
-
- public void restore(int flags) {
- this._templateName = CodexSequence.RestoreString();
- this._delay = CodexSequence.RestoreFloat();
- this._frequency = CodexSequence.RestoreFloat();
- this._maxThings = CodexSequence.RestoreInt();
- this._maxAlive = CodexSequence.RestoreInt();
- this.numThings = CodexSequence.RestoreInt();
- this.numAlive = CodexSequence.RestoreInt();
- }
-
- public void killed(int guid, int causeID, int captureID) {
- this.numAlive += -1;
- if (this.numAlive < this._maxAlive && (this._maxThings == 0 || this.numThings < this._maxThings)) {
- ((Codex)this).SetTimer(this._frequency);
- }
-
- }
-
- public void save(int flags) {
- CodexSequence.SaveString(this._templateName);
- CodexSequence.SaveFloat(this._delay);
- CodexSequence.SaveFloat(this._frequency);
- CodexSequence.SaveInt(this._maxThings);
- CodexSequence.SaveInt(this._maxAlive);
- CodexSequence.SaveInt(this.numThings);
- CodexSequence.SaveInt(this.numAlive);
- }
-
- public void timer(int timerID, float arg0, float arg1, float arg2, float arg3) {
- try {
- this.generatedGuid = this.generatorThing.SpawnThing(this._templateName);
- this.generatedThing = new CodexThing(this.generatedGuid);
- if (this.generatedThing == null) {
- return;
- }
-
- if (this.numFrames != 0 && Codex.IsActorGuid(this.generatedGuid)) {
- CodexActor actor = new CodexActor(this.generatedGuid);
- actor.SendActorToPos(this.pos, 150.0F);
- }
-
- if (this._maxThings != 0 && ++this.numThings >= this._maxThings) {
- return;
- }
-
- if (this._maxAlive != 0) {
- ((Codex)this).CaptureThing(this.generatedGuid);
- if (++this.numAlive >= this._maxAlive) {
- return;
- }
- }
-
- ((Codex)this).KillTimer();
- ((Codex)this).SetTimer(this._frequency);
- } catch (Exception var8) {
- CodexConsole.PrintException(((Throwable)var8).getMessage() + " in Generator [timer]");
- } catch (Error var9) {
- CodexConsole.PrintError(((Throwable)var9).getMessage() + " in Generator [timer]");
- }
-
- }
-
- public Generator(String templateName, float delay, float frequency, int maxThings, int maxAlive) {
- this._templateName = templateName;
- this._delay = delay;
- this._frequency = frequency;
- this._maxThings = maxThings;
- this._maxAlive = maxAlive;
- }
- }
-